package 笔试真题;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Union {
    Integer father;
    public Set<Integer> kids = new HashSet<>();

    public void add(int a, int b) {
        if (father == null) {
            father = a;
            kids.add(b);
        } else {
            if (a == father) kids.add(b);
            else if (b == father) kids.add(a);
            else if (kids.contains(a)) kids.add(b);
            else if (kids.contains(b)) kids.add(a);
        }
    }
}

public class Tengxun20211 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n-- > 0) {
            Union union = new Union();
            int m = scanner.nextInt();
            for (int i = 0; i < m; i++) {
                union.add(scanner.nextInt(),scanner.nextInt());
            }
            System.out.println(union.kids.size()+1);
        }
    }
}
